package com.mymall.serve.multicaster.listener;

import com.mymall.serve.multicaster.event.UpdateRankListEvent;
import com.mymall.serve.service.CacheService;
import com.mymall.serve.utils.CacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 事件监听器
 *
 * @author weiwei
 * @since 2020-04-16 13:55
 **/
@Slf4j
@EnableAsync
@Component
public class SelfEventListener {

    @Autowired
    private CacheService cacheService;

    @Autowired
    private CacheUtil cacheUtil;

    @Async("selfTaskExecutor")
    @EventListener(classes = {UpdateRankListEvent.class})
    public void updateRankEventListener(UpdateRankListEvent event){
        log.info(">>> 异步执行更新缓存");
        cacheService.updateRankEventListener(event.getKey(),event.getValue(),event.getScore());
    }
}
